//
//  sprite.h
//  gles1
//
//  Created by Realore Realore on 27.09.11.
//  Copyright 2011 Realore Studios. All rights reserved.
//

#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#import "texture.h"
#import "timer.h"


class OGLSprite: public CTimerCallbackInterface
{
private:
    
    

    float ratio;
    //
    
    float pointx1,pointx2,pointy1,pointy2;
    //
    
        int elapse;
    int animSpeed;
    bool playing;
    //texture coordinates
    float u1,v1,u2,v2;
    //rotation
    int rotation;
    //frames
    int totalFrames,currFrame;
    float frameSizeU,frameSizeV;
    //
    GLuint* Textures;
    CTimer* m_pTimer;
public:
    float x;
    float y;
    float width,height;

    OGLSprite(){};
    OGLSprite(int _width, int _height,int _x,int _y, Texture& tex);
    void Move(int _x, int _y);
    void InitTexture(char filename[]);
    void UpdateAnim();
    void InitTexture(Texture& tex);
    
    void SetFrame(int frame);
    void SetTextureCoords(float _u1,float _v1,float _u2,float _v2);
    void SetPolygon(float _width,float _height);
    
    void Zoom(float x1,float y1,float x2, float y2);
    
    void Play();
    void Stop();
    void GotoAndPlay(int frame);
    void GotoAndStop(int frame);
    
    bool HitPointTest(float _x,float _y);
    
    
    
    void Draw();
    void Update();
    Texture spriteTexture;
        
    int TextureID;
    GLfloat squareVert[8];    
    GLfloat texCoord[8];
    
    void startTest();
    
    void onTimer(const CTimer* timer);
    //zoom+pan trash
    bool drag;
    float currentDist;
    float currentDistPoints;
    float dist1;
    float rratio;
    float currCenterX,currCenterY;
protected:
    
};

//=============================
//sprite with childs system

class UISprite : public OGLSprite
{
private:
    int temp;
    long childsNum;
    UISprite* Parent;
public:
    UISprite(int _width, int _height,int _x,int _y, Texture& tex);
    UISprite(int _width, int _height,int _x,int _y, Texture& tex, UISprite* parent);
    UISprite(){};
    void Draw();
    void Move(int _x, int _y);
    void Update();
    
    bool isDrag;
    int offsetx,offsety;
    
    void AddChild(UISprite* src,int desiredName, UISprite* parent);
    UISprite* Childs[8192];
    void StartDrag(int _x,int _y);
    void StopDrag();
    int relative_x,relative_y;

};














